Added ASN.1 UPER and OER encoding#5031
Open
polybassa wants to merge 15 commits into
Open
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5031 +/- ##
==========================================
+ Coverage 80.13% 80.47% +0.33%
==========================================
Files 388 390 +2
Lines 96467 97990 +1523
==========================================
+ Hits 77308 78854 +1546
+ Misses 19159 19136 -23
🚀 New features to boost your workflow:
|
gpotter2
reviewed
Jul 6, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces ASN.1 UPER (Unaligned PER) and OER (Octet Encoding Rules) support in Scapy as groundwork for V2X / C-ITS, along with a broad set of interoperability, roundtrip, dissection, and fuzzing tests to validate the new encoders/decoders.
Changes:
- Add an OER codec implementation and expose OER/UPER via
scapy.all. - Extend
asn1fieldsto support OER/PER-specific encoding/decoding behaviors (tagging, PER presence bits, constrained sizes/ranges, etc.). - Add extensive UPER/OER test vectors, interoperability checks, fuzz tests, and cross-codec build/dissect coverage.
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
scapy/asn1/oer.py |
New OER codec implementation (lengths, integers, strings, tags, primitives). |
scapy/asn1fields.py |
Adds OER/PER-aware field encoding/decoding and PER decoder-path support for SEQUENCE/CHOICE/SEQUENCE OF. |
scapy/asn1/ber.py |
Uses configured default long-form sizing for explicit tags and SEQUENCE length encoding. |
scapy/all.py |
Exposes OER/UPER APIs via scapy.all. |
test/scapy/layers/uper_packets.py |
UPER packet/field build+roundtrip tests with fixed vectors. |
test/scapy/layers/uper_codec.py |
UPER primitive codec roundtrips + reference encode/decode vectors. |
test/scapy/layers/uper_helpers.py |
UPER low-level helper/bitstream tests (length determinant, constrained ints, etc.). |
test/scapy/layers/uper_iop.py |
UPER interoperability vectors vs reference encodings (asn1tools-derived). |
test/scapy/layers/uper_asn1scc_iop.py |
UPER interoperability vectors derived from ESA asn1scc test cases. |
test/scapy/layers/uper_fuzz.py |
UPER fuzz tests for packet and codec decode robustness. |
test/scapy/layers/oer_packets.py |
OER packet/field build+roundtrip tests with fixed vectors. |
test/scapy/layers/oer_iop.py |
OER interoperability vectors vs reference encodings (asn1tools-derived). |
test/scapy/layers/oer_fuzz.py |
OER fuzz tests for packet and codec decode robustness. |
test/scapy/layers/ber_packets.py |
BER packet/field build+roundtrip tests used for cross-codec parity coverage. |
test/scapy/layers/ber_codec.py |
BER helper/codec coverage tests (tagging, len/num/id, primitive codecs). |
test/scapy/layers/asn1_build_tests.py |
Cross-codec (BER/OER/PER) build and roundtrip tests. |
test/scapy/layers/asn1_dissect_tests.py |
Cross-codec dissection tests from fixed byte vectors. |
test/scapy/layers/asn1_coverage.py |
Additional coverage for UPER/OER and new asn1fields behaviors. |
test/scapy/layers/asn1.uts |
Wires new UPER/OER/BER tests into the UTS test suite. |
.config/codespell_ignore.txt |
Adds common ASN.1/per-related terms to codespell ignore list. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
added 14 commits
July 14, 2026 21:11
AI-Assisted: yes (Cursor AI)
AI-Assisted: yes (Cursor AI)
AI-Assisted: yes (Cursor AI)
AI-Assisted: yes (Cursor AI)
AI-Assisted: yes (Cursor AI)
AI-Assisted: yes (Cursor AI)
AI-Assisted: yes (Cursor AI)
AI-Assisted: yes (Cursor AI)
AI-Assisted: yes (Cursor AI)
AI-Assisted: yes (Cursor AI)
AI-Assisted: yes (Sonnet 5)
…ors. AI-Assisted: yes (Cursor AI)
OER SEQUENCE and SEQUENCE OF fields now propagate unconsumed bytes to their parent instead of raising, enabling nested structures and fields that follow a sequence within an enclosing SEQUENCE. AI-Assisted: yes (Cursor AI)
Use a valid --after date so the AI-Assisted trailer check runs, and route ASN1F_PACKET encode/decode through OER tagging like other ASN.1 fields. AI-Assisted: yes (Cursor AI)
AI-Assisted: no
Comment on lines
+360
to
+368
| codec = self.ASN1_tag.get_codec(pkt.ASN1_codec) | ||
| size_len = self.size_len or 0 | ||
| if pkt.ASN1_codec == ASN1_Codecs.OER and self.oer_unsigned: | ||
| return codec.enc( | ||
| item, size_len=size_len, oer_unsigned=True | ||
| ) # type: ignore[call-arg] | ||
| if pkt.ASN1_codec == ASN1_Codecs.PER: | ||
| return codec.enc(item, **self._uper_codec_kwargs(size_len)) | ||
| return codec.enc(item, size_len=size_len) |
Comment on lines
+1084
to
+1091
| def is_empty(self, pkt): | ||
| # type: (ASN1_Packet) -> bool | ||
| val = getattr(pkt, self._field.name, None) | ||
| if val is None: | ||
| return True | ||
| if getattr(self._field, "islist", 0) and val == []: | ||
| return True | ||
| return False |
Comment on lines
+321
to
+336
| real_tag = None | ||
| if explicit_tag is not None and len(s) > 0: | ||
| err_msg = ( | ||
| "OER_tagging_dec: observed tag 0x%.02x does not " | ||
| "match expected tag 0x%.02x (%s)" | ||
| ) | ||
| tag_class, tag_number, remainder = OER_tag_dec(s) | ||
| observed = tag_class | tag_number | ||
| if observed != explicit_tag: | ||
| if not safe: | ||
| raise OER_Decoding_Error( | ||
| err_msg % (observed, explicit_tag, _fname), | ||
| remaining=s) | ||
| real_tag = observed | ||
| s = remainder | ||
| return real_tag, s |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This encoders are a preparation to support V2X / C-ITS communication in Scapy.